package thread;

public class Demo11 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            //改代码是在lambda中（t线程的入口方法）中调用的
            //返回结果是t

            //判断是否终止
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hello");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //该线程掀桌了
//                    throw new RuntimeException(e);
                    break;
                }

            }
//            System.out.println(Thread.currentThread().getName());
            System.out.println("done");
        });
        t.start();

        //在main方法中调用，返回结果是main
//        Thread.currentThread();
//        System.out.println(Thread.currentThread().getName());

        Thread.sleep(3000);
        System.out.println("尝试终止t");
        t.interrupt();//主动终止
    }
}
